package org.teremail.schema;

public class Column {

    private final String name;
    private final DBType type;
    private final boolean isPrimaryKey;
    private final boolean isNullable;

    public Column(String name, DBType type, boolean isPrimaryKey,
            boolean isNullable) {
        this.name = name;
        this.type = type;
        this.isPrimaryKey = isPrimaryKey;
        this.isNullable = isNullable;
    }

    public String getName() {
        return name;
    }

    public DBType getType() {
        return type;
    }

    public String generateCreate(Dialect dialect) {
        StringBuilder sb = new StringBuilder();
        sb.append(name);
        sb.append(" ");
        sb.append(type.getCreate(dialect));
        if (!isNullable) {
            sb.append(" NOT NULL");
        }
        return sb.toString();
    }

    public boolean isPrimaryKey() {
        return isPrimaryKey;
    }

}
